package com.hot100.easy;

/**
 * @ClassName Demo18
 * @Description 移动零
 * @Author zt
 * @Date 15:57 2022/6/12
 * @Version 1.0
 **/
public class Demo18 {
    public static void main(String[] args) {
        int[] nums = {0,1,0,3,12};
        moveZeroes(nums);

    }

    public static void moveZeroes(int[] nums) {

        if(nums.length<=1){
            return;
        }
        //计算==0的个数
        int count=0;
        //新数组的位置
        int index=0;
        for (int i = 0; i < nums.length; i++) {
            if(nums[i]==0){
                count++;
            }
        }


        for (int i = 0; i <nums.length ; i++) {
            if(nums[i]!=0){
                nums[index++]=nums[i];
            }
        }
        for (int i = 1; i <=count ; i++) {
            nums[nums.length-i]=0;
        }
    }
}